package statistics;

import java.util.List;

import junit.framework.TestCase;
import numerics.LinearRegressionIO;
import numerics.WrongFileFormatException;

public class TestLinearRegressionIO extends TestCase {

	public void testInputFile1() throws WrongFileFormatException {
		List<double[]> data2test = LinearRegressionIO
				.parseInputFile("testcase1.txt");
		
		double[][] data = {
				{ 130,  186 },
				{ 650,  699 },
				{  99,  132 },
				{ 150, 272 },
				{ 128,  291 },
				{ 302,  331 },
				{  95,  199 },
				{ 945, 1890 },
				{ 368,  788 },
				{ 961, 1601 }
		};
		
		assertEquals(data.length, data2test.size());
		
		for (int i = 0; i < data2test.size(); ++i) {
			assertEquals(data[i][0], data2test.get(i)[0], 0.0);
			assertEquals(data[i][1], data2test.get(i)[1], 0.0);
		}
	}

	public void testInputFile2() throws WrongFileFormatException {
		List<double[]> data2test = LinearRegressionIO
				.parseInputFile("testcase2.txt");

		double[][] data = { 
				{ 130,  15.0 }, 
				{ 650,  69.9 }, 
				{  99,   6.5 },
				{ 150,  22.4 }, 
				{ 128,  28.4 }, 
				{ 302,  65.9 }, 
				{  95,  19.4 },
				{ 945, 198.7 }, 
				{ 368,  38.8 }, 
				{ 961, 138.2 }
		};

		assertEquals(data.length, data2test.size());

		for (int i = 0; i < data2test.size(); ++i) {
			assertEquals(data[i][0], data2test.get(i)[0], 0.0);
		}
	}
}
